package service

import (
	"fmt"
	"gitee.com/RocsSun/webhook/pkg/auth"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetAuth(ctx *gin.Context) {
	gitee := auth.NewGiteeOAuth()
	ctx.Status(http.StatusMovedPermanently)
	ctx.Header("Location", gitee.CallAuth())
}

func Callback(ctx *gin.Context) {
	query := ctx.DefaultQuery("code", "")
	if query == "" {
		ctx.JSON(401, gin.H{"msg": "code is null "})
		return
	}
	gitee := auth.NewGiteeOAuth()
	res, err := gitee.Callback(query)
	if err != nil {
		fmt.Println(err)
	}
	ctx.JSON(200, res)
}
